<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改订单')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-order-edit" th:object="${jtOrder}">
            <h4 class="form-header h4">订单信息</h4>
            <input name="orderId" th:field="*{orderId}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">订单号：</label>
                    <div class="col-sm-8">
                        <input name="orderNo" th:field="*{orderNo}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">物流公司：</label>
                    <div class="col-sm-8">
                        <input name="logisticsCompany" th:field="*{logisticsCompany}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">运单号：</label>
                    <div class="col-sm-8">
                        <input name="trackingNumber" th:field="*{trackingNumber}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">订单运费：</label>
                    <div class="col-sm-8">
                        <input name="freightAmount" th:field="*{freightAmount}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">购买数量：</label>
                    <div class="col-sm-8">
                        <input name="buyQty" th:field="*{buyQty}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">货币 CNY：</label>
                    <div class="col-sm-8">
                        <input name="currency" th:field="*{currency}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">订单金额：</label>
                    <div class="col-sm-8">
                        <input name="orderAmount" th:field="*{orderAmount}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">支付金额：</label>
                    <div class="col-sm-8">
                        <input name="paymentAmount" th:field="*{paymentAmount}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">优惠金额：</label>
                    <div class="col-sm-8">
                        <input name="reduceAmount" th:field="*{reduceAmount}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">收件人：</label>
                    <div class="col-sm-8">
                        <input name="receiver" th:field="*{receiver}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">收件人电话：</label>
                    <div class="col-sm-8">
                        <input name="phoneNumber" th:field="*{phoneNumber}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">国家：</label>
                    <div class="col-sm-8">
                        <input name="country" th:field="*{country}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">省：</label>
                    <div class="col-sm-8">
                        <input name="province" th:field="*{province}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">市：</label>
                    <div class="col-sm-8">
                        <input name="city" th:field="*{city}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">区：</label>
                    <div class="col-sm-8">
                        <input name="district" th:field="*{district}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">详细地址：</label>
                    <div class="col-sm-8">
                        <input name="fullAddress" th:field="*{fullAddress}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">邮编：</label>
                    <div class="col-sm-8">
                        <input name="postCode" th:field="*{zipCode}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">买家备注：</label>
                    <div class="col-sm-8">
                        <input name="buyerRemark" th:field="*{buyerRemark}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">买家备注：</label>
                    <div class="col-sm-8">
                        <input name="sellerRemark" th:field="*{sellerRemark}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">订单明细信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "business/order";
        $("#form-order-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-order-edit').serialize());
            }
        }

        $(function() {
            var options = {
                data: [[${jtOrder.jtOrderItemList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: i18n('serialNumber'),
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'productId',
                    align: 'center',
                    title: '产品ID',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].productId' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'skuId',
                    align: 'center',
                    title: 'SKU ID',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].skuId' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'prodName',
                    align: 'center',
                    title: '产品名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].prodName' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'skuName',
                    align: 'center',
                    title: 'sku名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].skuName' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'price',
                    align: 'center',
                    title: '价格',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].price' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'prodCount',
                    align: 'center',
                    title: '数量',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].prodCount' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'totalAmount',
                    align: 'center',
                    title: '商品总金额',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].totalAmount' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createBy',
                    align: 'center',
                    title: '创建者',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].createBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'createTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateBy',
                    align: 'center',
                    title: '更新者',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].updateBy' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'updateTime',
                    align: 'center',
                    title: '更新时间',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='jtOrderItemList[%s].updateTime' value='%s'>", index, value);
                        return html;
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                productId: "",
                skuId: "",
                prodName: "",
                skuName: "",
                price: "",
                prodCount: "",
                totalAmount: "",
                createBy: "",
                createTime: "",
                updateBy: "",
                updateTime: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>